package com.navinfo.collect.adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import android.widget.Toast
import androidx.recyclerview.widget.RecyclerView
import com.navinfo.collect.R

class NewDataAdapter(private val textList: ArrayList<String>) :
    RecyclerView.Adapter<NewDataAdapter.MyViewHolder>() {


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MyViewHolder {
        val view =
            LayoutInflater.from(parent.context).inflate(R.layout.adapter_item_text, parent, false);
        return MyViewHolder(view);
    }

    override fun onBindViewHolder(holder: MyViewHolder, position: Int) {
        val textpos = textList[position];
        holder.title.text = textpos;
        holder.itemView.setOnClickListener {
            Toast.makeText(holder.itemView.context, "${holder.title.text}", Toast.LENGTH_SHORT)
                .show()
        }
    }

    override fun getItemCount(): Int = textList.size

    class MyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val title: TextView = itemView.findViewById(R.id.adapter_item_text_id)
    }

    fun notifyDataSetChanged(list: ArrayList<String>){
        textList.clear()
        textList.addAll(list)
        notifyDataSetChanged()
    }

}